$(function() {
	doSearch();
});

function doSearch() {
	var startTime = $('#startTime').datebox('getValue');
	
	var yidongTn;
	var liantongTn;
	var dianxinTn;
	$.ajax({
		url : '/user/incr/analyzeData',
		data : {
			startTime : startTime
		},
		type : "POST",
		datatype : "json",
		async : true,
		success : function(data) {
			var pies = eval(data.pies);
			$.each(pies, function(index, mod) {
				if (mod.carrier == 0) {
					dianxinTn = mod.num;
				}
				if (mod.carrier == 1) {
					liantongTn = mod.num;
				}
				if (mod.carrier == 2) {
					yidongTn = mod.num;
				}
			});
			showHighChart(data.xAxis, data.yidongNum, data.liantongNum, data.dianxinNum, yidongTn, liantongTn, dianxinTn);
		}
	});
}

function showHighChart (x, yidongNum, liantongNum, dianxinNum, yidongTn, liantongTn, dianxinTn) {

	Highcharts.chart('container', {
	    title: {
	        text: '新增用户分析'
	    },
	    xAxis: {
	        categories: x
	    },
	    labels: {
	        items: [{
	            html: '各运营商新增用户',
	            style: {
	                left: '50px',
	                top: '15px',
	                color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
	            }
	        }]
	    },
	    series: [{
        	type: 'column',
        	name: '移动',
            data: yidongNum
        }, {
        	type: 'column',
        	name: '联通',
            data: liantongNum
        }, {
        	type: 'column',
        	name: '电信',
            data: dianxinNum
        }, {
            type: 'pie',
            name: '数量',
            data: [{
                name: '移动',
                y: yidongTn,
                color: Highcharts.getOptions().colors[0] 
            }, {
                name: '联通',
                y: liantongTn,
                color: Highcharts.getOptions().colors[1] 
            }, {
                name: '电信',
                y: dianxinTn,
                color: Highcharts.getOptions().colors[2] 
            }],
            center: [100, 80],
            size: 100,
            showInLegend: false,
            dataLabels: {
                enabled: false
            }
        }]
	});
}
